<template>
  <div class="component-teamCalc">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>添加施工队
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="main">
      <div class="component-main-left">
        <div class="box1">
          <span class="iconfont">&#xe67e;</span>
          <span>添加施工队</span>
          <div class="arrow"></div>
        </div>
      </div>
      <div class="component-main-right">
        <div class="box senInfo">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="施工队编号:" prop="num">
              <el-input v-model="ruleForm.num" placeholder="请输入施工队编号"></el-input>
            </el-form-item>
            <el-form-item label="施工队专业:" prop="checkList">
              <!--1-管道，2-线路，3-设备，4-熔纤，5-跳纤-->
              <el-checkbox-group v-model="ruleForm.checkList">
                <el-checkbox label="1">管道</el-checkbox>
                <el-checkbox label="2">线路</el-checkbox>
                <el-checkbox label="3">设备</el-checkbox>
                <el-checkbox label="4">熔纤</el-checkbox>
                <!--<el-checkbox label="5">跳纤</el-checkbox>-->
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="施工队名称:" prop="userName">
              <el-input style="width: 280px;margin-right: 4px;margin-left: 0px;" v-model="ruleForm.userName" placeholder="请输入施工队长真实姓名"></el-input>施工队
            </el-form-item>
            <el-form-item label="负责区域:" prop="region">
              <el-cascader
                :options="options"
                v-model="ruleForm.region"
                style="width:326px;margin-left: 0px;"
                class="wd400">
              </el-cascader>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import area from '@/assets/js/area.js'
export default {
    name:"teamCalc",
    data(){
        return {
          options:area, //省市区
          ruleForm: {
            num:'',
            checkList:[],
            userName:'',
            region:[],
          },
          rules: {
            num: [
              { required: true, message: "请输入施工队编号", trigger: "blur" },
              { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
            ],
            checkList: [
              { type: 'array',required: true, message: "请选择施工队专业", trigger: "change" },
            ],
            userName: [
              { required: true, message: "请输入施工队名称", trigger: "blur" },
              { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
            ],
            region:[
              { type: 'array',required: true, message: "请输入负责区域", trigger: "change" },
            ]
          },

          workarea: ["", "", ""], //省市区
        };
    },
    methods:{
      //添加
      dataInit(){
        let that = this;
        let suCb = function(res){
          that.$message({
            message: '添加成功',
            type: 'success'
          });
          that.$router.push({name:'teamInfo'})
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          orgNumber: this.ruleForm.num, //施工队编号
          workFunction: this.ruleForm.checkList.join(","), //施工队类型
          orgName: this.ruleForm.userName, //施工队长ID
          orgProvince: this.ruleForm.region[0],
          orgCity: this.ruleForm.region[1],
          orgArea: this.ruleForm.region[2],
        }
        let palyParam = {
          url: "/api/web/sysOrg/addProTeam",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //省市区
      getArea(value, selectedData) {
        const areaName = selectedData.map(item => item.label)
        this.args = [...areaName]
        console.log(this.value2)
      },
      //表单提交
      submitForm(formName){
        console.log(this.ruleForm);
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.dataInit();
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
    }
}
</script>

<style scoped>
  .main{
    overflow: hidden;
    width: 1100px;
    margin: 1px auto;
    border: 1px solid #e4e4e4;
    border-left:none;
    border-top: none;
  }
  .component-main-left {
    width: 180px;
    border: 1px solid #e4e4e4;
    padding-top: 50px;
    float: left;
    height: 600px;
    border-top: none;
    border-bottom: none;
  }
  .box1 {
    position: relative;
    width: 175px;
    height: 50px;
    text-align: left;
    line-height: 50px;
    background-color: #9ea7b4;
    color: #fff;
    padding-left: 5px;
  }
  .box1 .arrow {
    position: absolute;
    width: 0;
    height: 0;
    top: -40px;
    left: 180px;
    border-width: 25px 0 25px 25px;
    border-style: solid;
    border-color: transparent transparent transparent #9ea7b4; /*透明 透明 透明 灰*/
    margin: 40px auto;
  }
  .component-main-right{
    float: left;
  }
  .box{
    margin-left: 120px;
    margin-top: 80px;
    outline: none;
  }
  .el-button--primary{
    background-color: #1ABC9C;
    border-color: #1ABC9C;
  }

</style>
